package com.houg.testorderapi.service.ipml;

import com.houg.testorderapi.common.constants.Base;
import com.houg.testorderapi.mapper.OrderMapper;
import com.houg.testorderapi.model.entity.Order;
import com.houg.testorderapi.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: NALHOUG
 * @Time: 2019/11/8 16:42
 * @Explain:
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public Order selectByOrderId(String orderId) {
        return orderMapper.selectByOrderId(orderId);
    }

    @Override
    public Order selectOne(Order order) {
        return selectOne(order);
    }

    @Override
    public int insert(Order order) {
        return insert(order);
    }

    @Override
    public int closeOrder(String orderId) {
        return orderMapper.closeOrder(orderId);
    }

    @Override
    public int payState(String orderId,int orderState) {
        return orderMapper.payState(orderId,orderState);
    }

    @Override
    public Order selectByUserId(String userId) {
        return orderMapper.selectByUserId(userId);
    }

    /**
     * 已支付
     * @param order 用户标识
     * @return 订单对象
     */
    private Order haveToPay(Order order){
        order.setOrderState(Base.HAVE_TO_PAY);
        return order;
    }
    /**
     * 未支付
     * @param order 用户标识
     * @return 订单对象
     */
    private Order notBay(Order order){
        order.setOrderState(Base.NOT_PAY);
        return order;
    }
}
